import cv2
import sys

try:
    mediafile = sys.argv[1]
except:
    mediafile = 'test.mp4'

try:
    frame_num = int(sys.argv[2])
except:
    frame_num = 98

try:
    output = sys.argv[3]
except:
    output = ''.join([mediafile.split('.')[0],'_',str(frame_num),'.jpg'])

media = cv2.VideoCapture(mediafile)
n = 0
while n<1000:
    _,img = media.read()
    n += 1
    if n==frame_num:
        #_,img = cv2.threshold(img,121,255,cv2.THRESH_BINARY)
        sec = img[:,:]
        #cv2.imwrite(outputfile,img)
        cv2.imwrite(output,sec)

